package com.boot.nio;

import java.awt.*;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NioClient {
    public static void main(String[] args) throws IOException, InterruptedException {
        SocketChannel channel = SocketChannel.open();
        channel.configureBlocking(false);
        InetSocketAddress address = new InetSocketAddress("127.0.0.1",6666);
        if(!channel.connect(address)){
            while (!channel.finishConnect()){
                Thread.sleep(2000l);
                System.out.println("连接中....");
            }
        }
        String msg = "Nio test....";
        ByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());
        channel.write(buffer);
        System.in.read();
    }
}
